//
//  CSNumberUtils.swift
//  Cycling
//
//  Created by CSS on 4/1/23.
//

import Foundation

extension TimeInterval {
    
    /**
        分:60 小时: 60 * 60 天: 12 * 60 * 60
     */
    var formatRemainingString: String {
        if self < 60 {
            return "\(Int(self))秒"
        }
        var remaining = self
        return [("天", 12.0 * 60 * 60), ("小时" , 60.0 * 60), ("分钟" , 60.0)].reduce("", {
            var componentNum: Int
            if remaining < $1.1 {
                componentNum = 0
            } else if remaining > 60 {
                componentNum = .init(floor(remaining / $1.1))
            } else {
                componentNum = .init(ceil(remaining / $1.1))
            }
            remaining -= Double(componentNum) * $1.1
            if componentNum == 0 {
                return $0
            }
            return $0 + "\(componentNum)\($1.0)"
        })
    }
    
}
